import java.util.ArrayList;
import java.util.Collections;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-11-28
 * Time: 18:39
 */
public class Test4 {
    public static void bucketSort(int[] array) {
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        for(int i = 0; i < array.length;i++) {
            min = Math.min(min,array[i]);
            max = Math.max(max,array[i]);
        }
        int bucketCount = (max - min)/array.length + 1;
        ArrayList<ArrayList<Integer>> list = new ArrayList<>();
        for (int i = 0; i < bucketCount; i++) {
            list.add(new ArrayList<>());
        }
        for (int i = 0; i < array.length; i++) {
            int val = (array[i] - min)/array.length;
            list.get(val).add(array[i]);
        }
        for(int i = 0; i < bucketCount; i++) {
                Collections.sort(list.get(i));
        }
        int index = 0;
        for (int i = 0; i < bucketCount; i++) {
            for (int j = 0; j < list.get(i).size(); j++) {
                array[index++] = list.get(i).get(j);
            }
        }
    }

    public static void main(String[] args) {
        int[] array = {19,48,6,7,32,4,3,45,62,7,21,4,5,52,64,44};
        bucketSort(array);
        for (int num : array) {
            System.out.print(num + " ");
        }
    }
}
